define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'redeem/code/index' + location.search,
                    add_url: 'redeem/code/add',
                    edit_url: 'redeem/code/edit',
                    del_url: 'redeem/code/del',
                    multi_url: 'redeem/code/multi',
                    import_url: 'redeem/code/import',
                    table: 'redeem_code',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5')}, formatter: Table.api.formatter.normal},
                        {field: 'num', title: __('Num')},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $('#c-type').change(function(){
                if($(this).val() == 1){
                    $(".system_prop_json").show();
                    $(".num").show();
                    $(".di_json").show();
                    $(".zhe_json").show();
                }else if($(this).val() == 2){
                    $(".system_prop_json").hide();
                    $(".num").show();
                    $(".di_json").hide();
                    $(".zhe_json").hide();
                }else if($(this).val() == 3){
                    $(".system_prop_json").show();
                    $(".num").hide();
                    $(".di_json").hide();
                    $(".zhe_json").hide();
                }else if($(this).val() == 4){
                    $(".system_prop_json").hide();
                    $(".num").hide();
                    $(".di_json").show();
                    $(".zhe_json").hide();
                }else if($(this).val() == 5){
                    $(".system_prop_json").hide();
                    $(".num").hide();
                    $(".di_json").hide();
                    $(".zhe_json").show();
                }
            });
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
				$(document).on("fa.event.appendfieldlist", "#second-table .btn-append", function (e, obj) {
					//绑定动态下拉组件
					Form.events.selectpage(obj);
				});
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
